import * as React from "react";
import { apiUserLogin } from "apis/module/sys";
import { config } from "types";
import { getVersion } from "@/api";

export default () => {
  const [version, setVersion] = React.useState<string>();
  const [token, setToken] = React.useState<string>();

  const getData = async () => {
    const { data } = await getVersion();
    setVersion(data.dataInfo.version);
  };

  const login = async () => {
    const res = await apiUserLogin({
      username: "ZWD284",
      password: "123456",
    });
    const { code, data, exception } = res;
    if (code === config.API_SUCCESS) {
      setToken(data.access_token);
    } else {
      setToken(exception);
    }
  };

  React.useEffect(() => {
    getData();
    login();
  }, []);

  return (
    <>
      version:{version}, token:{token}
    </>
  );
};
